//扫雷模拟
#include <bits/stdc++.h>
using namespace std;
#define N  150
int main()
{
	ios::sync_with_stdio(0),cin.tie (0),cout.tie(0);\
	int n=0, m=0;
	cin>>n;
	cin>>m;
	//导入地雷
	int arr[N][N] = {0};
	int arrcpy[N][N] = {0};
	for(int i = 1;i <= n; i++)
	{
		for(int j = 1;j <= m; j++)
		{
			cin >> arr[i][j];
		}
	}
	//遍历判断
	for(int i = 1;i <= n; i++)
	{
		for(int j = 1;j <= m; j++)
		{
			if(arr[i][j]==1)
				arrcpy[i][j] = 9;
			else
			{
				int sum = 0;
				for(int _i = max(i-1,1); _i <= i+1;_i++)
				{
					for(int _j = max(j-1,1); _j <= j+1;_j++)
					{
						sum+=arr[_i][_j];
						
					}
				}
				arrcpy[i][j] = sum;
			}
			
		}
	}
//输出
	for(int i = 1;i <= n; i++)
	{
		for(int j = 1;j <= m; j++)
		{
			cout << arrcpy[i][j] <<" ";
		}
		cout <<endl;
	}
	
	return 0;
}
